package com.atguigu.lease.admin.controller;

import com.atguigu.lease.admin.service.PaymentTypeService;
import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.bean.PaymentType;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("admin/payment")
@Tag(name = "支付方式管理模块")
public class PaymentInfoController {
    @Autowired
    private PaymentTypeService paymentTypeService;

    @GetMapping("list")
    @Operation(summary = "查询所有支付方式")
    public Result<List<PaymentType>> list(){
        return Result.ok(paymentTypeService.list());
    }

    @GetMapping("page/{pageNum}/{pageSize}")
    @Operation(summary = "分页查询支付方式")
    public Result<Page<PaymentType>> page(@Parameter(description = "页码") @PathVariable("pageNum") long pageNum,
                                          @Parameter(description = "每页记录数") @PathVariable("pageSize") long pageSize){
        return Result.ok(paymentTypeService.page(new Page<PaymentType>(pageNum,pageSize)));
    }

    @PostMapping("saveOrUpdate")
    @Operation(summary = "新增或更新支付方式")
    public Result saveOrUpdate(@RequestBody PaymentType paymentType){
       /* paymentType.setCreateTime(new Date());
        paymentType.setUpdateTime(new Date());*/
        return Result.ok(paymentTypeService.saveOrUpdate(paymentType));
    }

    @DeleteMapping("deleteById")
    @Operation(summary = "根据Id删除支付方式")
    public Result deletedById(
            @Parameter(description = "主键",in = ParameterIn.QUERY,required = true)
            @RequestParam("id") Integer id){
        return Result.ok(paymentTypeService.removeById(id));
    }

}
